package socket;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Client {
    private Socket socket;
    public static void main(String[] args) {

        Client client = new Client();
        client.start();
    }
    public void start(){

        try(OutputStream out = socket.getOutputStream();) {
            Scanner scanner = new Scanner(System.in);
            byte[] date;
            System.out.println("请输入要传输的数据");
            date = scanner.nextLine().getBytes(StandardCharsets.UTF_8);
            out.write(date.length);
            out.write(date);

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public Client(){
        try {
            System.out.println("正在链接服务端");
            socket = new Socket("localhost", 8088);
            System.out.println("链接成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}







































